home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 26 / AACD 26.iso / AACD / System / XFD / Developer / Sources / ASM / CoMp.a < prev    next >
Encoding:
Text File  |  2001-09-16  |  3.6 KB  |  167 lines

  1. ; CoMp XFD slave by Kyzer/CSG
  2. ; (Resident De/Compressor (C) 1994 Simon_Gibbs@Standard.Embassy.Com)
  3. ; Huffman-only compression!
  4. ;
  5. ; CoMp crunched data format:
  6. ; ULONG ID: "CoMp"
  7. ; ULONG (("H" or "h") << 24) | (unpacked length)
  8. ;
  9.  
  10.     IFD    TEST
  11.     include    xfdExeHead.a
  12.     ENDC
  13.  
  14.     include    libraries/xfdmaster.i
  15.  
  16. ForeMan    dc.l    $70FF4E75,XFDF_ID    ; id
  17.     dc.w    XFDF_VERSION        ; foreman version
  18.     dcb.w    5,0            ; reserved stuff
  19.     dc.l    CoMpdata        ; first slave
  20.  
  21. CoMpdata
  22.     dc.l    0
  23.     dc.w    2,39
  24.     dc.l    CoMpdata_name
  25.     dc.w    XFDPFF_DATA!XFDPFF_RECOGLEN!XFDPFF_USERTARGET,0
  26.     dc.l    CoMpdata_recog,CoMpdata_decrunch,CoMpdata_scan,CoMpdata_verify
  27.     dc.l    0,18
  28.  
  29. CoMpdata_recog
  30.     cmp.l    #"CoMp",(a0)+
  31.     bne.s    .fail
  32.     move.l    (a0)+,d0        ; d0 = unpacked length and "H"<<24
  33.     rol.l    #8,d0
  34.     cmp.b    #"h",d0
  35.     beq.s    .ok1
  36.     cmp.b    #"H",d0
  37.     bne.s    .fail
  38. .ok1    asr.l    #8,d0
  39.     beq.s    .fail            ; fail if unpacked length = 0
  40.     move.l    d0,xfdrr_FinalTargetLen(a1)
  41.     add.l    #(6*256*2)+4,d0
  42.     move.l    d0,xfdrr_MinTargetLen(a1)
  43.     clr.l    xfdrr_MinSourceLen(a1)
  44.     moveq    #1,d0            ; return success
  45.     rts
  46. .fail    moveq    #0,d0
  47.     rts
  48.  
  49. CoMpdata_decrunch
  50.     movem.l    d2-d7/a2-a6,-(sp)
  51.     move.l    a0,a6
  52.     move.l    xfdbi_SourceBuffer(a6),a0    ; a0 = input ptr
  53.     move.l    xfdbi_UserTargetBuf(a6),a1    ; a1 = output ptr
  54.     move.l    xfdbi_TargetBufSaveLen(a6),d7    ; d7 = output length
  55.  
  56.  
  57.     ; go to end of decrunched file and align to 4 bytes
  58.     ; this becomes our decrunch table pointer
  59.     move.l    a1,d0
  60.     add.l    d7,d0
  61.     addq.l    #3,d0
  62.     andi.w    #-4,d0
  63.     move.l    d0,a2                ; A2 = decrunch table
  64.  
  65.     move.b    4(a0),d0    ; D0 = table on-disk format ("H" or "h")
  66.     addq.l    #8,a0
  67.     moveq    #0,d1
  68.     move.b    (a0)+,d1    ; D1 = number of leaf-nodes (byte entries)
  69.     moveq    #0,d2
  70.     move.b    (a0)+,d2    ; D2 = number of branch-nodes (W/L entries)
  71.     moveq    #1,d6
  72.     add.l    d1,d6
  73.     add.l    d2,d6        ; D6 = total table entries + 1 (root entry)
  74.  
  75.  
  76.     ; build decrunch table (each entry 6 bytes)
  77.     move.l    a2,a3
  78. .tab1    move.b    (a0)+,(a3)+    ; $AA
  79.     clr.b    (a3)+        ; $00
  80.     clr.l    (a3)+        ; $00000000
  81.     dbra    d1,.tab1    ; = $AA0000000000
  82.  
  83.     cmp.b    #"h",d0
  84.     beq.s    .smltab
  85. .bigtab    clr.w    (a3)+        ; $00, $00
  86.     move.b    (a0)+,(a3)+    ; $AA
  87.     move.b    (a0)+,(a3)+    ; $BB
  88.     move.b    (a0)+,(a3)+    ; $CC
  89.     move.b    (a0)+,(a3)+    ; $DD
  90.     dbra    d2,.bigtab    ; = $0000AABBCCDD
  91.     bra.s    .tabok
  92. .smltab    clr.w    (a3)+        ; $00, $00
  93.     clr.b    (a3)+        ; $00
  94.     move.b    (a0)+,(a3)+    ; $AA
  95.     clr.b    (a3)+        ; $00
  96.     move.b    (a0)+,(a3)+    ; $BB
  97.     dbra    d2,.smltab    ; = $000000AA00BB
  98. .tabok
  99.  
  100.     ; A0 = src ptr
  101.     ; A1 = dest ptr
  102.     ; A2 = table ptr
  103.     ; D6 = tree-root index
  104.     ; D7 = output bytes to go
  105.  
  106.     ; D0 = current node
  107.     ; D1 = bit/byte counter
  108.     ; D2 = current byte/bit
  109.  
  110.     move.w    d6,d0        ; current node = root node
  111.     moveq    #8-1,d1        ; reset number of bits left in D2
  112.     move.b    (a0)+,d2    ; fill up D2
  113.  
  114. .loop    add.l    d0,d0        ; d0 *= 6
  115.     move.l    d0,a5
  116.     add.l    d0,d0
  117.     add.l    a5,d0
  118.     move.l    2(a2,d0.w),d3    ; d3 = left/right branch indicies of this node
  119.     bne.s    .branch
  120.  
  121.     ; if both have nil indicies, it's a leaf
  122.     move.b    (a2,d0.w),(a1)+    ; write out the literal
  123.     move.w    d6,d0        ; back to the root node
  124.  
  125.     subq.l    #1,d7        ; one less byte
  126.     bne.s    .loop        ; if any more left, go back again
  127.     bra.s    .done
  128.  
  129. .branch    asl.b    #1,d2        ; clock out the next bit
  130.     bcs.b    2$        ; set = LSW branch, clear = MSW branch
  131.     swap    d3
  132. 2$    move.w    d3,d0        ; set new node index
  133.  
  134.     dbra    d1,.loop    ; if still bits left, back to loop
  135.     moveq    #8-1,d1        ; reset number of bits left in D2
  136.     move.b    (a0)+,d2    ; fill up D2
  137.     bra.s    .loop
  138.  
  139. .done    moveq    #1,d0    ; success
  140.     movem.l    (sp)+,d2-d7/a2-a6
  141.     rts
  142.  
  143. CoMpdata_scan
  144.     moveq   #0,d0
  145.     cmp.l   #"CoMp",(a0)
  146.     bne.s    .fail
  147.     moveq    #1,d0
  148. .fail    rts
  149.  
  150. CoMpdata_verify
  151.     move.l    4(a0),d0
  152.     rol.l    #8,d0
  153.     cmp.b    #"h",d0
  154.     beq.s    .ok1
  155.     cmp.b    #"H",d0
  156.     bne.s    .fail
  157. .ok1    asr.l    #8,d0
  158.     tst.l    d0
  159.     beq.s    .fail
  160.     rts
  161. .fail    moveq    #0,d0
  162.     rts
  163.  
  164.  
  165. CoMpdata_name    dc.b    '(CoMp) Data Cruncher',0
  166.         dc.b    '$VER: CoMp 1.1 (14.10.2000) by <kyzer@4u.net>'
  167.